﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Sinacor.Infra.Common.ErrorLogging;
using System.Xml;

namespace Sinacor.Infra.Service.ErrorLogging
{
    public class ServiceEnvironmentData : LoginEnvironmentData
    {
        [XmlAttribute]
        public Uri ServiceAddress { get; set; }

        protected override string ToStringOverride()
        {
            StringBuilder logData = new StringBuilder(base.ToStringOverride());

            logData.AppendLine();
            logData.AppendFormat("ServiceAddress:\t{0}", this.ServiceAddress);
            logData.AppendLine();

            if (this.DbEnvironment != null)
            {
                logData.Append(this.DbEnvironment.ToString());
            }

            return logData.ToString();
        }

        public override void WriteTo(XmlWriter writer)
        {
            base.WriteTo(writer);

            writer.WriteElementString("ServiceAddress", this.ServiceAddress.ToString());

            if (this.DbEnvironment != null)
            {
                this.DbEnvironment.WriteTo(writer);
            }
        }
    }
}
